﻿#pragma once
#include "Node.hpp"
#include "Object/Object.hpp"
#include "Syntax/Object/Boolean.hpp"
#include "Text/TextSpan.hpp"
#include <cstddef>
#include <string>

class SyntaxToken : public SyntaxNode
{
public:
    SyntaxToken() : SyntaxToken(SyntaxKind::Eof, "", nullptr, 0){};

    SyntaxToken(SyntaxKind type, std::string text, SharedObject value, size_t position)
        : SyntaxNode(type, "SyntaxToken: " + text), Text(text), _IsMissing(text.empty()), Value(value), Position(position), Span(position, text.length()){};

    virtual std::string GetName() const { return this->Text; }

    // std::string toString() {
    //   std::stringstream oss;
    //   oss << "SyntaxToken{ Kind: " << (int)this->GetKind() << " , name: \""
    //       << Text << "\"}\r\n";
    //   return oss.str();
    // }

    // 判断是否存在期望的种类;
    bool isMatch(std::vector<SyntaxKind> kinds)
    {
        for (SyntaxKind kind : kinds)
        {
            if (kind == this->GetKind())
                return true;
        }
        return false;
    }
    // 判断是否存在期望的种类;
    bool isMatch(SyntaxKind kind)
    {
        if (kind == this->GetKind())
            return true;
        return false;
    }
    TextSpan     GetTextSpan() { return this->Span; }
    size_t       GetPosition() { return this->Position; }
    std::string  GetTextName() { return this->Text; }
    SharedObject GetTextValue() { return this->Value; }
    bool         IsMissing() { return this->_IsMissing; }

private:
    std::string Text;
    TextSpan    Span;

    bool _IsMissing;

    SharedObject Value;
    size_t       Position;
};

typedef std::shared_ptr<SyntaxToken> SharedToken;